﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Admintool.Infrastructure
{
    public class ConsoleHelper
    {
        public static void ShowMessage(Exception ex)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(ex.Message);
            Console.ResetColor();
        }

        public static void ShowMessage(string message, ConsoleColor color)
        {
            Console.ForegroundColor = color;
            Console.WriteLine(message);
            Console.ResetColor();
        }

        public static void ShowMessage(string format, ConsoleColor color, params object[] args)
        {
            Console.ForegroundColor = color;
            Console.WriteLine(format, args);
            Console.ResetColor();
        }
        public static T GetValue<T>(string source)
        {
            T t = default(T);
            try
            {
                t = (T)Convert.ChangeType(source, typeof(T));
            }
            catch (Exception)
            {
            }
            return t;
        }


        public static T GetValue<T>(string source, T defaultVal)
        {
            T t = default(T);
            try
            {
                t = (T)Convert.ChangeType(source, typeof(T));
            }
            catch (Exception)
            {
                t = defaultVal;
            }
            return t;
        }




    }
}
